home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Inspectors / InspectMe / ThingInspector.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  134 lines

  1. // ThingInspector.m
  2. // By Kevin Brain (ksbrain@zeus.UWaterloo.ca)
  3.  
  4. // Acts as an intermediary between the Thing1 and Thing2 
  5. // (Tank) attribute inspector view controls (layed out in
  6. // the file ThingInspector.nib) and the objects they inspect. 
  7.  
  8. #import "ThingInspector.h"
  9. #import "InspectMeApp.h"
  10. #import "Thing1.h"
  11. #import "Tank.h"
  12. #import "InspectorManager.h"
  13. #import <appkit/Control.h>            // displaying attributes 
  14.  
  15. @implementation ThingInspector
  16.  
  17. static id theThingInspector = nil;    // just one per class 
  18.  
  19. // only a single instance of this class is permitted
  20. //  use [ThingInspector new] to return the single instance
  21.  
  22. + new
  23. {
  24.     if (!theThingInspector) {
  25.         theThingInspector = self = [super new];
  26.         [NXApp loadNibSection:"ThingInspector.nib" owner:self];
  27.         }
  28.     else 
  29.         self = theThingInspector;
  30.     return self;
  31. }
  32.  
  33. - setupInspectors:(id)mainInspector
  34. {
  35.     inspectorManager = [NXApp inspectorManager];
  36.     thing1InspectorNum = [inspectorManager 
  37.         addInspector:(id)thing1InspectorBox 
  38.         title:(const char *)"Thing 1 Inspector"
  39.         atLocation:LOWERLEFTX :LOWERLEFTY
  40.         cached:YES cacheWindow:[thing1InspectorBox window]];
  41.  
  42.     tankInspectorNum = [inspectorManager 
  43.         addInspector:(id)tankInspectorBox 
  44.         title:(const char *)"Thing 2 Inspector"
  45.         atLocation:LOWERLEFTX :LOWERLEFTY
  46.         cached:YES cacheWindow:[tankInspectorBox window]];
  47.                 
  48.     return self;
  49. }
  50.  
  51. - setCurrentParameterReceiver:(id)newCurrent
  52. {
  53.     currentParameterReceiver = newCurrent;
  54.     return self;
  55. }
  56.     
  57. - (unsigned int)thing1InspectorNum
  58. {
  59.     return thing1InspectorNum;
  60. }
  61.  
  62. - (unsigned int)tankInspectorNum
  63. {
  64.     return tankInspectorNum;
  65. }
  66.  
  67. - reflectThing1Attributes:(id)theObject
  68. {
  69.     if(!theObject) return self;
  70.     
  71.     [outNumber setIntValue:[theObject number]];
  72.     [outSize setIntValue:[theObject size]];
  73.  
  74.     switch([theObject shape]) {
  75.         case SHAPE_CIRCLES:
  76.             [outShape setTitle:"Circles"];
  77.             break;
  78.         case SHAPE_SQUARES:
  79.             [outShape setTitle:"Squares"];
  80.             break;
  81.         }
  82.     return self;
  83. }
  84.  
  85. - reflectTankAttributes:(id)theObject
  86. {
  87.     char buffer[15];
  88.     if(!theObject) return self;
  89.     
  90.     sprintf(buffer,"%8.1f",[theObject capacity]);
  91.     [outCapacity setStringValue:buffer];
  92.     sprintf(buffer,"%8.1f",[theObject holding]);
  93.     [outHolding setStringValue:buffer];
  94.  
  95.     return self;
  96. }
  97.  
  98. /* Setting ingredient attribute values */
  99. /*   Targets of inspector controls   */
  100. /* NOTE: No range checking has been added to these methods yet. */
  101.  
  102. - inspSetNumber:sender
  103. {
  104.     [currentParameterReceiver setNumber:[sender intValue]];
  105.     return self;
  106. }
  107.  
  108. - inspSetSize:sender
  109. {
  110.     [currentParameterReceiver setSize:[sender intValue]];
  111.     return self;
  112. }
  113.  
  114. - inspSetShape:sender
  115. {
  116.     [currentParameterReceiver setShape:[[sender selectedCell] tag]];
  117.     return self;
  118. }
  119.  
  120. - inspSetCapacity:sender
  121. {
  122.     [currentParameterReceiver setCapacity:[sender floatValue]];
  123.     return self;
  124. }
  125.  
  126. - inspSetHolding:sender
  127. {
  128.     [currentParameterReceiver setHolding:[sender floatValue]];
  129.     return self;
  130. }
  131.  
  132.     
  133. @end
  134.